package com.itheima.controller;

import com.itheima.domain.ClassQuerParam;
import com.itheima.domain.PageResult;
import com.itheima.domain.Result;
import com.itheima.domain.pojo.Clazz;
import com.itheima.service.ClazzService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.List;
@RequestMapping("/clazzs")
@RestController
public class ClazzController {
    @Autowired
    private ClazzService clazzService;
//    查询班级列表
    @GetMapping("/list")
    public Result list() {
        List<Clazz> clazzList= clazzService.list();
        return Result.success(clazzList);
    }
//添加班级
    @PostMapping
    public Result add(@RequestBody Clazz clazz){
        clazzService.add(clazz);
        return Result.success();
    }
    //分页查询班级信息
    @GetMapping
  public   Result page(ClassQuerParam classQuerParam){
       PageResult<Clazz> pageResult= clazzService.page(classQuerParam);
        return Result.success(pageResult);
    }
    //根据id进行删除班级
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Integer id){
        clazzService.delete(id);
        return Result.success();
    }

    //修改班级信息：1.数据回显功能。
    //2.修改班级信息功能

    //1.数据回显功能
    @GetMapping("/{id}")
    public Result selectById(@PathVariable Integer id){
       Clazz clazz=  clazzService.selectById(id);
        return Result.success( clazz);
    }
    //2.修改班级信息功能
    @PutMapping
    public Result update(@RequestBody Clazz clazz){
        clazzService.update(clazz);
        return Result.success();
    }


}
